package com.clkj.nangang.util;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.drawable.Drawable;

import com.clkj.nangang.app.CustomApplication;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


/**
 * Created by Administrator on 2015/7/1.
 */
public class Res {

    public static int getDrawableIdFromName(String paramString) {
        return CustomApplication.getInstance().getResources().getIdentifier(paramString, "drawable", CustomApplication.getInstance().getPackageName());
    }

    public static int getMipmapIdFromName(String paramString) {
        return CustomApplication.getInstance().getResources().getIdentifier(paramString, "mipmap", CustomApplication.getInstance().getPackageName());
    }

    public static int getColorIdFromName(String paramString) {
        return CustomApplication.getInstance().getResources().getIdentifier(paramString, "color", CustomApplication.getInstance().getPackageName());
    }



    public static Drawable getDrawable(int paramInt) {
        return CustomApplication.getInstance().getResources().getDrawable(paramInt);
    }

    public static String getString(int paramInt){
        return CustomApplication.getInstance().getResources().getString(paramInt);
    }


    public static  int getColor(int paramInt)
    {
        return CustomApplication.getInstance().getResources().getColor(paramInt);
    }

    public static  int getDimen(int paramInt)
    {
        return CustomApplication.getInstance().getResources().getDimensionPixelSize(paramInt);
    }

    public static String getAssetsJson(Context mContext, String fileName) {
        StringBuilder sb = new StringBuilder();
        AssetManager am = mContext.getAssets();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    am.open(fileName)));
            String next = "";
            while (null != (next = br.readLine())) {
                sb.append(next);
            }
        } catch (IOException e) {
            e.printStackTrace();
            sb.delete(0, sb.length());
        }
        return sb.toString().trim();
    }
}
